<?php
/**
 * 邮件发送
 */
namespace api\home\controller;
use cmf\controller\RestBaseController;
use think\Config;
use PHPMailer\PHPMailer;
class SendMailController extends RestBaseController{
	public $isSMTP;
	public $SMTPDebug;
	public $Host;
	public $Port;
	public $SMTPAuth;
	public $Username;
	public $Password;
	public function __construct(){
		$this->isSMTP = Config::get('isSMTP');
		$this->SMTPDebug = Config::get('SMTPDebug');
		$this->Host = Config::get('Host');
		$this->Port = Config::get('Port');
		$this->SMTPAuth = Config::get('SMTPAuth');
		$this->Username = Config::get('Username');
		$this->Password = Config::get('Password');
		$this->SMTPSecure = Config::get('SMTPSecure');
		$this->isSMTP = Config::get('isSMTP');
		$this->IsHTML = Config::get('IsHTML');
	}
	public function sendMail(){
		$mail = new PHPMailer();
		$mail->Host = $this->Host;
		$mail->SMTPAuth = $this->SMTPAuth;
		$mail->Username = $this->Username;
		$mail->Password = $this->Password;
		$mail->Port = $this->Port;
		$mail->SMTPSecure = $this->SMTPSecure;
		if($this->isSMTP){
			$mail->IsSMTP();
		}		
		$mail->IsHTML($this->IsHTML);
		$mail->CharSet='utf-8';
		$mail->Encoding = "base64";
		$mail->SMTPDebug = $this->SMTPDebug;
		$mail->setFrom($this->Username);

		
		$mail->addAddress('870144911@qq.com');
		$mail->Subject = '黄建成，有你的紧急消息，收到请回复'.time();
		$mail->msgHTML('<p style="color:red;">黄建成，有你的紧急消息，收到请回复'.time().'</p>');
		$mail->AltBody = '黄建成，有你的紧急消息，收到请回复'.time();
		if(!$mail->send()){
			echo $mail->ErrorInfo;
		}else{
			echo 'success';
		}
	}
}